<template>
  <div v-if="visible" class="download-modal-overlay" @click.self="handleClose">
    <div class="download-modal">
      <button class="modal-close-btn" @click="handleClose">
        <img :src="closeIcon" alt="关闭" class="close-icon-img">
      </button>
      
      <div class="download-icon-wrapper">
        <div class="download-icon-box">
          <img :src="downloadIcon" alt="下载" class="download-icon-img">
        </div>
      </div>
      
      <h2 class="download-modal-title">确定需要下载该作品</h2>
      
      <div class="download-points">
        <span class="points-amount">30共享分</span>
      </div>
      
      <div class="account-info">
        <span class="account-text">(共享分账户: </span>
        <span class="account-balance">58,230,752</span>
        <span class="account-text"> </span>
        <span class="recharge-link" @click="handleRecharge">马上充值</span>
        <span class="account-text">)</span>
      </div>
      
      <div class="work-thumbnail">
        <img :src="workImage" :alt="workTitle">
      </div>
      
      <button class="confirm-download-btn" @click="handleConfirm">确定</button>
      
      <div class="agreement-checkbox">
        <label class="checkbox-label">
          <input type="checkbox" v-model="localAgreeAgreement" class="checkbox-input">
          <span class="checkbox-custom">
            <img v-if="localAgreeAgreement" :src="checkboxIcon" alt="已选中" class="checkbox-icon">
          </span>
          <span class="checkbox-text">
            同意<nuxt-link to="#" class="agreement-link">《网站协议》</nuxt-link>协议
          </span>
        </label>
      </div>
      
      <div class="download-tips">
        如有问题请于24小时内发起投诉,24小时后系统将自动确认交易并支付给卖家。
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DownloadModal',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    workImage: {
      type: String,
      required: true
    },
    workTitle: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      localAgreeAgreement: true,
      closeIcon: require('~/assets/images/img/A-2-1-PC登陆-注册_slices/关闭.png'),
      downloadIcon: require('~/assets/images/img/B-02作品_详情页_slices/手机-符号组合.png'),
      checkboxIcon: require('~/assets/images/img/A-2-1-PC登陆-注册_slices/符号组合.png')
    }
  },
  watch: {
    visible(newVal) {
      if (newVal) {
        this.localAgreeAgreement = true
      }
    }
  },
  methods: {
    handleClose() {
      this.$emit('close')
    },
    handleRecharge() {
      this.$emit('recharge')
    },
    handleConfirm() {
      if (!this.localAgreeAgreement) {
        this.$message.warning('请先同意网站协议')
        return
      }
      this.$emit('confirm')
    }
  }
}
</script>

<style scoped>
.download-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.download-modal {
  position: relative;
  background: white;
  border-radius: 8px;
  width: 370px;
  height: 520px;
  padding: 40px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 10;
}

.close-icon-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.download-icon-wrapper {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

.download-icon-box {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.download-icon-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.download-modal-title {
  text-align: center;
  font-size: 18px;
  font-weight: 400;
  color: #2E2E30;
  margin-bottom: 16px;
}

.download-points {
  text-align: center;
  margin-bottom: 16px;
}

.points-amount {
  font-size: 16px;
  color: #19D8B6;
}

.account-info {
  text-align: center;
  font-size: 12px;
  color: #2E2E30;
  margin-bottom: 40px;
}

.account-balance {
  color: #2E2E30;
}

.recharge-link {
  margin-left: 8px;
  color: #19D8B6;
  cursor: pointer;
  text-decoration: none;
}

.recharge-link:hover {
  text-decoration: underline;
}

.work-thumbnail {
  width: 95px;
  height: 95px;
  margin: 0 auto 40px;
  border-radius: 2px;
}

.work-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.confirm-download-btn {
  background: #2E2E30;
  color: white;
  border: none;
  padding: 11px 48px;
  border-radius: 182px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.3s;
  margin: 0 auto 30px;
  display: block;
  width: auto;
}

.confirm-download-btn:hover {
  background: #555;
}

.agreement-checkbox {
  margin-bottom: 8px;
  text-align: center;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: #666;
}

.checkbox-input {
  display: none;
}

.checkbox-custom {
  width: 14px;
  height: 14px;
  margin-right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s;
  border: 1px solid #ddd;
  border-radius: 50%;
  box-sizing: border-box;
}

.checkbox-input:checked + .checkbox-custom {
  border: none;
}

.checkbox-icon {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.agreement-link {
  color: #666;
  text-decoration: none;
}

.agreement-link:hover {
  color: #19D8B6;
  text-decoration: underline;
}

.download-tips {
  font-size: 12px;
  color: #666;
  line-height: 1.6;
  text-align: center;
}
</style>

